package com.example.studentmag1.controller;


import com.example.studentmag1.entity.Students;
import com.example.studentmag1.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-01-08
 */
@RestController
@RequestMapping("//students")
public class StudentsController {
    @Autowired
    private StudentsService studentsService;

    @GetMapping("/list")
    public List<Students> list(){
        return this.studentsService.list();
    }

    @PutMapping("/insert")
    public boolean insert(@RequestBody Students students){
        return this.studentsService.saveOrUpdate(students);
    }
    @DeleteMapping("/delete/{Id}")
    public boolean delete(@PathVariable("Id") Integer Id){//PathVariable 占位符
        return  this.studentsService.removeById(Id);
    }
    @GetMapping("/select/{id}")
    public Students select(@PathVariable("id") Integer id){
        return this.studentsService.getById(id);
    }
    @PutMapping("/update")
    public boolean update(@RequestBody Students students){
        return this.studentsService.updateById(students);
    }

}

